// __PUBLIC__/js/page/admin/content/feedback
require(['../../common'], function() {
  require(['content.feedback'])
})

define('content.feedback', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';

  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init()

  $(document)
    .on('click', '.A_del', function(e) {
      e.preventDefault()
      delFeedback(getASelected(this))
    })
    .on('click', '#J_del', function(e) {
      e.preventDefault()
      delFeedback(getSelected())
    })
    .on('click', '#J_search', function(e) {
      e.preventDefault()
      sureSearchFeedback()
    })

  function getSelected() {
    var selected = mygrid.getSelected()
    if (!selected.count) {
      alert(lang.pleaseSelectAData)
      return
    }
    return selected
  }

  function getASelected(t) {
    var current = mygrid.getCurrent(t)
    var selected = {
      id: [current.id],
      index: [current.index]
    }
    return selected
  }

  function delFeedback(selected) {
    $.post(APP + '?app=admin&m=Content&a=delFeedback', {
      ids: selected.id.join()
    }).done(function(res) {
      if (res == '1') {
        alert(lang.delSuccess)
        mygrid.del(selected.index)
      } else {
        alert(lang.delFails)
      }
    })
  }

  function sureSearchFeedback() {
    var id = $('#id').val()
    var uid = $('#uid').val()
    var data = $('#content').val()
    var str_get = '&id=' + id + '&uid=' + uid + '&data=' + data
    location.href = APP + '?app=admin&m=Content&a=feedback' + str_get
  }
})
